package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.bo.CollectAddBo;
import com.cskaoyan.bean.bo.CollectListBo;
import com.cskaoyan.bean.pojo.MallUser;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.CollectListVo;
import com.cskaoyan.bean.vo.TypeVo;
import com.cskaoyan.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: ycb
 * @description: 收藏模块
 * @time: 2021/7/12 17:18
 */
@RestController
@RequestMapping("wx/collect")
public class CollectController {

    @Autowired
    CollectService collectService;

    /**
     * @Author ycb
     * @description: 收藏列表
     * @Date 17:19 2021/7/12
     * url:http://182.92.235.201:8083/wx/collect/list?type=0&page=1&size=10
     */
    @RequestMapping("list")
    public BaseRespVo list(CollectListBo collectListBo){
        Subject subject = SecurityUtils.getSubject();
        MallUser principal = (MallUser) subject.getPrincipal();

        CollectListVo collectListVo = collectService.getColletList(principal.getId(),collectListBo.getType(),collectListBo.getPage(),collectListBo.getSize());
        return BaseRespVo.ok(collectListVo);
    }


    /**
     * @Author ycb
     * @description: 收藏商品增删
     * @Date 20:34 2021/7/12
     * url: http://182.92.235.201:8083/wx/collect/addordelete
     */
    @RequestMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody CollectAddBo collectAddBo){
        Subject subject = SecurityUtils.getSubject();
        MallUser user = (MallUser) subject.getPrincipal();
        TypeVo typeVo = collectService.addOrDeleteColletion(user.getId(),collectAddBo.getType(),collectAddBo.getValueId());
        return BaseRespVo.ok(typeVo);
    }
}